import request from '@/utils/request'

/**
 * 获取用户信息接口
 * @return Promise
 */
export const getUserInfoAPI = () => {
  return request({
    url: '/userinfo'
  })
}

/**
 * 退出登录接口
 * @param ids
 * @return Promise
 */
export const logoutAPI = () => {
  return request({
    url: '/userinfo/logout/'
  })
}

/**
 * 获取用户类型接口
 * @return Promise
 */
export const getUserInfoTypeAPI = () => {
  return request({
    url: '/userinfo/type'
  })
}

/**
 * 获取用户手机号验证码接口
 * @return Promise
 */
export const getCodeAPI = () => {
  return request({
    url: '/userinfo/old_code'
  })
}

/**
 * 获取新手机号验证码接口
 * @param phone
 * @return Promise
 */
export const newCodeAPI = (data) => {
  return request({
    url: '/userinfo/new_code',
    method: 'POST',
    data
  })
}

/**
 * 验证验证码接口
 * @param {Object} data: {phone, code}
 * @return Promise
 */
export const validCodeAPI = (data) => {
  return request({
    url: '/userinfo/valid_code',
    method: 'POST',
    data
  })
}

/**
 * 修改用户密码接口
 * @param {Object} data: {oldPassword, newPassword}
 * @return Promise
 */
export const updatePasswordAPI = (data) => {
  return request({
    url: '/userinfo/password',
    method: 'PATCH',
    data
  })
}

/**
 * 修改用户手机号接口
 * @param {Object} data: {phone, code}
 * @return Promise
 */
export const updatePhoneAPI = (data) => {
  return request({
    url: '/userinfo/phone',
    method: 'PATCH',
    data
  })
}
